package com.jair.jairaiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class LoveAppVectorStoreConfig {

    @Resource
    private LoveAppDocumentLoder loveAppDocumentLoder;

    @Bean
    public VectorStore loveAppVectorStore(EmbeddingModel dashScopeEmbeddingModel){
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashScopeEmbeddingModel)
                .build();
        //加载Markdown文档向量化并且存储到向量数据库
        List<Document> documents = loveAppDocumentLoder.loadMarkDowns();
        simpleVectorStore.add(documents);
        return simpleVectorStore;

    }
}
